<script><br />
var request = false;<br />
try {<br />
request = new XMLHttpRequest();<br />
} catch (trymicrosoft) {<br />
try {<br />
request = new ActiveXObject("Msxml2.XMLHTTP");<br />
} catch (othermicrosoft) {<br />
try {<br />
request = new ActiveXObject("Microsoft.XMLHTTP");<br />
} catch (failed) {<br />
request = false;<br />
}<br />
}<br />
}<br />
<br />
if (!request)<br />
alert("Erro ao inicializar o XMLHttpRequest!");<br />
<br />
function ObterPag1() {<br />
var url = "05-dados1.json";<br />
request.open("GET", url, true);<br />
request.onreadystatechange = updatePage;<br />
request.send(null);<br />
}<br />
<br />
function ObterPag2() {<br />
var url = "05-dados2.json";<br />
request.open("GET", url, true);<br />
request.onreadystatechange = updatePage;<br />
request.send(null);<br />
}<br />
<br />
function ObterPag3() {<br />
var url = "05-dados3.json";<br />
request.open("GET", url, true);<br />
request.onreadystatechange = updatePage;<br />
request.send(null);<br />
}<br />
<br />
function updatePage() {<br />
if (request.readyState == 4) { /* navigation completed */<br />
if (request.status == 200) { /* 0 = erro */<br />
var response = request.responseText;<br />
document.getElementById("Texto").value = response;<br />
} else<br />
alert("Erro de acesso"); // + request.status vem sempre zero quando dá erro<br />
//alert("o texto de retorno é " + request.responseText);<br />
}<br />
}<br />
<br />
</script><br />
<br />
<button type="button" class="btn" onClick="ObterPag1();">Página 1</button><br />
<button type="button" class="btn" onClick="ObterPag2();">Página 2</button><br />
<button type="button" class="btn" onClick="ObterPag3();">Página 3</button>